﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DynamicChart.Data;

namespace Sinochem.TMS.PurchaseChartService
{
    public class DepartmentQuery : IChartDataQuery
    {
        public ChartData GetData(DateRange dateRange, QueryParameter parameter)
        {
            ChartData chart = new ChartData
            {
                Caption = "部门采购前十分析",
                Type = ChartType.Pie
            };

            if (dateRange.Mode == "y")
            {
                chart.Caption = string.Format("部门采购签约情况分析（{0}年）",
                    dateRange.CurrentDate.Year);
            }
            else
            {
                chart.Caption = string.Format("部门采购签约情况分析（{0}年{1}月）",
                    dateRange.CurrentDate.Year,
                    dateRange.CurrentDate.Month);
            }

            ChartSeriesData seriesData = new ChartSeriesData();
            chart.SeriesData.Add(seriesData);
            seriesData.Caption = "金额";
            string[] colors = new string[]{
                "#66E0FF",
                "#70DAF5",
                "#ADEBEB",
                "#B1C7E7",
                "#3C72C4",
                "#F08080",
                "#FFA54F",
                "#EEC900",
                "#E066FF",
                "#A2B5CD",
            };
            for (int i = 0; i < 10; i++)
            {
                System.Threading.Thread.Sleep(100);
                seriesData.Items.Add(new ChartDataItem
                {
                    Name = "部门" + i.ToString(),
                    Color = colors[i],
                    Value = new Random().Next(120, 1100),
                    NavigationUrl = string.Empty
                });
            }

            return chart;
        }
    }
}
